<template>
  <div class="module_balance">
    <van-panel>
      <div slot="header" class="header_panel van-panel__header">
        <div class="van-cell__title">
          余额
          <span class="monDetail" @click="$router.push({name: 'balance-list'})">余额明细</span>
        </div>
        <div class="van-cell__value" @click="pickMoney">
          <u>提现</u>
        </div>
      </div>
      <div class="van-panel__content content_text">
        <b>{{balance.toFixed(2)}}</b>
      </div>
    </van-panel>
    <!-- <van-cell icon="" title="积分"> -->
    <van-panel>
      <div slot="header" class="header_panel van-panel__header">
        <div class="van-cell__title">总积分: {{user.points}}</div>
        <div class="van-cell__value">
          <u @click="$router.push({name: 'jifen-list'})">积分明细</u>
          <u @click="$router.push({name: 'jifen-convert'})">积分兑换</u>
        </div>
      </div>
    </van-panel>
    <van-cell v-if="isteam" icon="gold-bean" title="累计佣金" :to="'/user/commission/list'" isLink>
      <div slot="right-icon">
        <span class="commission_text">
          <span>{{totalCommission.toFixed(2)}}</span>
        </span>
        <van-icon name="arrow" class="van-cell__right-icon"/>
      </div>
    </van-cell>
    <pick-money :visible="showPickMoney" @visibleChange="showPickMoney=$event"/>
  </div>
</template>

<script>
import { Panel } from "vant";
import PickMoney from "./pick-money";
import { COMMISSION_TOTAL } from "@/api/user";

export default {
  name: "module-balance",

  data() {
    return {
      showPickMoney: false,
      totalCommission: 0
    };
  },

  computed: {
    balance() {
      return this.user.credit2;
    },
    isteam() {
      return this.user.isteam === 3;
    }
  },

  created() {
    this.user = this.getUser();
    if (this.user.isteam === 3) {
      this.$reqGet(
        COMMISSION_TOTAL,
        { memberId: this.user.id },
        { hideLoading: true }
      ).then(res => {
        this.totalCommission = res.data.data;
      });
    }
  },

  methods: {
    pickMoney() {
      this.showPickMoney = true;
    }
  },

  components: {
    [Panel.name]: Panel,
    [PickMoney.name]: PickMoney
  }
};
</script>

<style lang="scss" scoped>
.header_panel {
  line-height: 24px;
  padding: 10px 15px 0 15px;
  display: flex;
  height: 30px;
}
.content_text {
  color: $red;
  font-size: 32px;
  text-align: center;
  position: relative;
  padding: 0 20px 10px 20px;

  ::before {
    content: "¥";
    font-size: 12px;
    margin-right: 3px;
  }
}

.commission_text {
  color: $red;
  font-size: 18px;
  ::before {
    content: "¥";
    font-size: 8px;
    margin-right: 3px;
  }
}
</style>
<style lang="scss">
.module_balance {
  .van-cell__title {
    .monDetail {
      text-decoration: underline;
      padding-left: 15px;
      color: #f44;
    }
  }
}
</style>

